package org.flexthinker.binding.ui.form.binding.flex
{
    import mx.utils.StringUtil;

    import org.flexthinker.binding.bean.UpdateStrategy;
    import org.flexthinker.binding.ui.form.binding.support.FieldBinder;

    import spark.components.supportClasses.ListBase;

    /**
     * Binder implementation for all visual components extending <code>ListBase</code>.
     * These components are: <code>ButtonBar</code>, <code>ComboBox</code>, <code>DropDownList</code>,
     * <code>List</code> and <code>TabBar</code>.
     *
     * <code>DefaultFlexBinderFactory</code> automatically serves this <code>ListBinder</code> for these components.
     *
     *  <code>ListBinder</code> generates a <code>Binding</code> on the <code>selectedItem</code> property of the
     *  </code>component</code>. The <code>UpdateStrategy</code> is <code>READ_WRITE</code>.
     */
    public class ListBinder extends FieldBinder
    {
        public function ListBinder(component:ListBase, formProperty:String)
        {
            super(component,  formProperty);
            if ( !component.hasOwnProperty("selectedItem"))
            {
                 throw new ArgumentError( StringUtil.substitute( "Could not use ListBinder on {0}", component) );
            }
            super.componentProperty = "selectedItem";
            super.updateStrategy = UpdateStrategy.READ_WRITE;
        }
    }
}
